<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/includes/site_defaults.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/database/db.php');
LoginUser();

// get the top dealers

$qry = "SELECT id, dealer_name, city, state_province FROM dealerships ORDER BY num_views DESC LIMIT 10";
mysql_select_db($db_name, $db);
$top_dealers = mysql_query($qry) or die(mysql_error());


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="robots" content="nofollow, noindex" />
	<title>UnOfficial Green Auto Market Home Page</title>
	<link href="<?php echo $site_root."css/green.css"; ?>" rel="stylesheet" type="text/css" />
	<script src="js/jquery.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/jquery-ui.js" type="text/javascript" charset="utf-8"></script>
</head>

<body>
	<script type="text/javascript">
	$(document).ready(function(){
		$('#login_form').submit(function(){
			var username = $('input#email').val();
			var password = $('input#password').val();
			var remember = $('input#remember').attr("checked");
			var dataString = "email="+username+"&password="+password+"&remember="+remember;
			$.post('login.php', dataString, function(data) {
				if (data == 'Login Succeeded.') {
					location.reload(true);
				} else {
					$("input#email").focus();
					$("#login_err_msg").html(data).effect("pulsate", {times: 2}, 1000);	
						
				}
			});			
			return false;
		});
	});
	</script>

	
	
	<?php include($header); ?>
	<?php include($navigation); ?>
	<div id="wrapper">
		<div id="leftcol">
			<h4>Top Dealers</h4>

			<ul>
				<?php while ($dealer = mysql_fetch_assoc($top_dealers)) {  ?>
					<li>
						<a href="dealer_detail.php?dealer_id=<?php echo $dealer["id"] ?>">
							<?php echo $dealer["dealer_name"].", ".$dealer["state_province"] ?>
						</a>
					</li>
					<?php } 

				mysql_free_result($top_dealers);

				?>
			</ul>
			

		</div><!--End of Left Column-->

		<div id="content">
			<div id="findcar">				
				<img src="<?php echo $images."find_a_car.png"; ?>" alt="Green Car" />
			</div>

			<div id="finddealer">
				<img src="<?php echo $images."find_a_dealer.png"; ?>" alt="Two people exchanging keys and money." />
			</div>

		</div><!--End of Content-->
		
		<div id="rightcol">
			<?php if (!CheckLoggedIn()): ?>

				<div id="login_form_wrapper">
					<h4>Login</h4>
					<form action="#" method="post" accept-charset="utf-8" id="login_form">                        							
						<table id="login_form_table">
							<tr>
								<td>Email Address</td>
								<td><input type="text" name="email" value="" id="email" tab_stop="1" size="10"/></td>
							</tr>
							<tr>
								<td>Password</td>
								<td><input type="password" name="password" value="" id="password" tab_stop="2" size="10"/></td>
							</tr>

							<tr>
								<td colspan="2">
									<input type="checkbox" name="remember" checked="checked" id="remember" tab_stop="2"/>
									&nbsp; Remember Me
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<input type="submit" value="Login" />
								</td>
							</tr>
						</table>
					</form>
					<div id="login_err_msg"></div>
					<br/>
					<a href="edit_account.php?id=-1">Create an Account</a><br />
					By creating an account you can:
					<ul>
						<li>List your dealership</li>
						<li>Create a classified ad</li>
					</ul>

				</div>

			<?php endif; ?>
			
			
		</div> <!-- End of Right Column -->


	</div><!--End of Wrapper-->
	<?php include($footer); ?>
</body>

</html>